home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
language
/
examples.zoo
/
closette
/
newcl.lsp
< prev
Wrap
Lisp/Scheme
|
1991-10-22
|
5KB
|
131 lines
;;;-*-Mode:LISP; Package:NEWCL; Base:10; Syntax:Common-lisp -*-
;;; This is the file newcl.lisp
(in-package 'newcl :use '(lisp))
(shadow '(defun fmakunbound fboundp))
(export '(fdefinition defun fmakunbound fboundp print-unreadable-object))
;;; New macros to support function names like (setf foo).
(lisp:defun setf-function-symbol (function-specifier)
(if (consp function-specifier)
; make a unique symbol from the function-specifier
(let ((sym1 (first function-specifier))
(sym2 (second function-specifier)))
(intern (concatenate 'string "(" (symbol-name sym1) " " (symbol-name sym2) ")")
(symbol-package sym2)
) )
function-specifier
) )
(lisp:defun fboundp (function-specifier)
(if (consp function-specifier)
(lisp:fboundp (setf-function-symbol function-specifier))
(lisp:fboundp function-specifier)
) )
(lisp:defun fdefinition (function-specifier)
(if (consp function-specifier)
(lisp:symbol-function (setf-function-symbol function-specifier))
(lisp:symbol-function function-specifier)
) )
(lisp:defun fmakunbound (function-specifier)
(if (consp function-specifier)
(lisp:fmakunbound (setf-function-symbol function-specifier))
(lisp:fmakunbound function-specifier)
) )
(defsetf fdefinition (function-specifier) (new-value)
`(set-fdefinition ,function-specifier ,new-value)
)
(lisp:defun set-fdefinition (function-specifier new-value)
(if (consp function-specifier)
(let ((setf-symbol (setf-function-symbol function-specifier)))
(setf (symbol-function setf-symbol) new-value)
(eval
`(defsetf ,(second function-specifier) (&rest all-args) (new-value)
(list* ',setf-symbol new-value all-args)
)
)
new-value
)
(setf (symbol-function function-specifier) new-value)
) )
(defmacro defun (name formals &body body)
(cond ((symbolp name) `(lisp:defun ,name ,formals ,@body))
((and (consp name) (eq (first name) 'setf))
(let ((setf-symbol (setf-function-symbol name)))
`(progn
(lisp:defun ,setf-symbol ,formals ,@body)
(defsetf ,(second name) ,(cdr formals) (,(car formals))
(list ',setf-symbol ,@formals)
) )
))
(t (error "Kein Funktionsname: ~S" name))
) )
#| Minimal tests:
(macroexpand '(defun (setf foo) (nv x y) (+ x y)))
(defun (setf baz) (new-value arg)
(format t "setting value of ~A to ~A" arg new-value))
(macroexpand '(setf (baz (+ 2 2)) (* 3 3)))
|#
;;;
;;; print-unreadable-object
;;;
;;; print-unreadable-object is the standard way in the new Common Lisp
;;; to generate #< > around objects that can't be read back in. The option
;;; (:identity t) causes the inclusion of a representation of the object's
;;; identity, typically some sort of machine-dependent storage address.
#+CLISP
(let* ((poke-array-2 (make-array 10))
(poke-array-1 (make-array 10 :displaced-to poke-array-2 :adjustable t))
(poke-array (make-array 10 :displaced-to poke-array-1))
(poke-bignum #x400000000000)) ; Bignum, das 6 Bytes Daten braucht
(progn
(when (< (nth-value 1 (room)) 100) (gc))
(adjust-array poke-array-1 1 :displaced-to (make-array 1))
(setq poke-bignum (+ poke-bignum 1)) ; neues Bignum allozieren
)
; Nun sieht's im Speicher so aus:
; poke-array-1 poke-bignum
; |Self|Länge|1 Elt.| |Self|Länge|Wert|
; 0 4 8 12 12 16 18 24
; Diese Speicher-Anordnung wird auch von der GC nicht durcheinandergebracht.
(defun address-of (obj)
(setf (aref poke-array 3) obj)
(logand poke-bignum #xFFFFFFFF)
)
)
(defmacro print-unreadable-object ((object stream &key type identity) &body body)
(let ((stream. (gensym))
(object. (gensym)))
`(let ((,stream. ,stream)
(,object. ,object))
(write-char #\# ,stream.)
(write-char #\< ,stream.)
,@(when type `((write (type-of ,object.) :stream stream)))
,@(when (and type (or body identity)) `((write-char #\Space ,stream.)))
,@body
,@(when (and identity body) `((write-char #\Space ,stream.)))
,@(when identity
#+Genera `((format ,stream. "~O" (si:%pointer ,object.)))
#+Lucid `((format ,stream. "~O" (sys:%pointer ,object.)))
#+Excl `((format ,stream. "~O" (excl::pointer-to-fixnum ,object.)))
#+:coral `((format ,stream. "~O" (ccl::%ptr-to-int ,object.)))
#+CLISP `((format ,stream. "#x~6,'0X" (logand (address-of ,object.) #xFFFFFF)))
)
(write-char #\> ,stream.)
nil
)
) )